package com.szp.drug.component.controller;

import com.github.pagehelper.PageInfo;
import com.szp.drug.component.service.api.DrugRoleService;
import com.szp.drug.entity.DrugRole;
import com.szp.drug.util.ResultEntity;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 角色前端控制器
 * @author SuZePing
 * @create 2021-01-19 8:07
 * @E-mail suzeping10@126.com
 */
@Slf4j
@RestController
@RequestMapping("/role")
public class DrugRoleController {

	@Autowired
	private DrugRoleService roleService;

	/**
	 * 分页获取role
	 * @param keyword
	 * @param pageNum
	 * @param pageSize
	 * @return
	 */
	@PostMapping("/get/page.json")
	public ResultEntity<PageInfo<DrugRole>> getPageInfo(
			@RequestParam(value = "keyword",defaultValue = "") String keyword,
			@RequestParam(value = "pageNum",defaultValue = "1") String pageNum,
			@RequestParam(value = "pageSize",defaultValue = "5") String pageSize
	){
		return roleService.getPageInfo(keyword, pageNum, pageSize);
	}

	/**
	 * 新增role(并返回新增后总数量)
	 * @param role
	 * @return
	 */
	@PostMapping("/save.json")
	public ResultEntity<Integer> saveRole(DrugRole role){
		return roleService.saveRole(role);
	}

	/**
	 * 修改role
	 * @param role
	 * @return
	 */
	@PostMapping("/edit.json")
	public ResultEntity<String> editRole(DrugRole role){
		return roleService.editRole(role);
	}

	/**
	 * 批量删除role[通过roleId数据进行删除]
	 * @param roleIds
	 * @return
	 */
	@PostMapping("/del.json")
	public ResultEntity<String> removeRole(@RequestBody List<String> roleIds){
		return roleService.removeRole(roleIds);
	}
}